﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace Terraria.Cinematics
{
	// Token: 0x02000489 RID: 1161
	public class Film
	{
		// Token: 0x170002BA RID: 698
		// (get) Token: 0x0600272B RID: 10027 RVA: 0x0001B670 File Offset: 0x00019870
		public int Frame
		{
			get
			{
				return this._frame;
			}
		}

		// Token: 0x170002BB RID: 699
		// (get) Token: 0x0600272C RID: 10028 RVA: 0x0001B678 File Offset: 0x00019878
		public int FrameCount
		{
			get
			{
				return this._frameCount;
			}
		}

		// Token: 0x170002BC RID: 700
		// (get) Token: 0x0600272D RID: 10029 RVA: 0x0001B680 File Offset: 0x00019880
		public int AppendPoint
		{
			get
			{
				return this._nextSequenceAppendTime;
			}
		}

		// Token: 0x170002BD RID: 701
		// (get) Token: 0x0600272E RID: 10030 RVA: 0x0001B688 File Offset: 0x00019888
		public bool IsActive
		{
			get
			{
				return this._isActive;
			}
		}

		// Token: 0x0600272F RID: 10031 RVA: 0x0001B690 File Offset: 0x00019890
		public void AddSequence(int start, int duration, FrameEvent frameEvent)
		{
			this._sequences.Add(new Film.Sequence(frameEvent, start, duration));
			this._nextSequenceAppendTime = Math.Max(this._nextSequenceAppendTime, start + duration);
			this._frameCount = Math.Max(this._frameCount, start + duration);
		}

		// Token: 0x06002730 RID: 10032 RVA: 0x0001B6CD File Offset: 0x000198CD
		public void AppendSequence(int duration, FrameEvent frameEvent)
		{
			this.AddSequence(this._nextSequenceAppendTime, duration, frameEvent);
		}

		// Token: 0x06002731 RID: 10033 RVA: 0x0049450C File Offset: 0x0049270C
		public void AddSequences(int start, int duration, params FrameEvent[] frameEvents)
		{
			foreach (FrameEvent frameEvent in frameEvents)
			{
				this.AddSequence(start, duration, frameEvent);
			}
		}

		// Token: 0x06002732 RID: 10034 RVA: 0x00494534 File Offset: 0x00492734
		public void AppendSequences(int duration, params FrameEvent[] frameEvents)
		{
			int nextSequenceAppendTime = this._nextSequenceAppendTime;
			foreach (FrameEvent frameEvent in frameEvents)
			{
				this._sequences.Add(new Film.Sequence(frameEvent, nextSequenceAppendTime, duration));
				this._nextSequenceAppendTime = Math.Max(this._nextSequenceAppendTime, nextSequenceAppendTime + duration);
				this._frameCount = Math.Max(this._frameCount, nextSequenceAppendTime + duration);
			}
		}

		// Token: 0x06002733 RID: 10035 RVA: 0x0001B6DD File Offset: 0x000198DD
		public void AppendEmptySequence(int duration)
		{
			this.AddSequence(this._nextSequenceAppendTime, duration, new FrameEvent(Film.EmptyFrameEvent));
		}

		// Token: 0x06002734 RID: 10036 RVA: 0x0001B6F8 File Offset: 0x000198F8
		public void AppendKeyFrame(FrameEvent frameEvent)
		{
			this.AddKeyFrame(this._nextSequenceAppendTime, frameEvent);
		}

		// Token: 0x06002735 RID: 10037 RVA: 0x00494598 File Offset: 0x00492798
		public void AppendKeyFrames(params FrameEvent[] frameEvents)
		{
			int nextSequenceAppendTime = this._nextSequenceAppendTime;
			foreach (FrameEvent frameEvent in frameEvents)
			{
				this._sequences.Add(new Film.Sequence(frameEvent, nextSequenceAppendTime, 1));
			}
			this._frameCount = Math.Max(this._frameCount, nextSequenceAppendTime + 1);
		}

		// Token: 0x06002736 RID: 10038 RVA: 0x0001B707 File Offset: 0x00019907
		public void AddKeyFrame(int frame, FrameEvent frameEvent)
		{
			this._sequences.Add(new Film.Sequence(frameEvent, frame, 1));
			this._frameCount = Math.Max(this._frameCount, frame + 1);
		}

		// Token: 0x06002737 RID: 10039 RVA: 0x004945E8 File Offset: 0x004927E8
		public void AddKeyFrames(int frame, params FrameEvent[] frameEvents)
		{
			foreach (FrameEvent frameEvent in frameEvents)
			{
				this.AddKeyFrame(frame, frameEvent);
			}
		}

		// Token: 0x06002738 RID: 10040 RVA: 0x00494610 File Offset: 0x00492810
		public bool OnUpdate(GameTime gameTime)
		{
			if (this._sequences.Count == 0)
			{
				return false;
			}
			foreach (Film.Sequence sequence in this._sequences)
			{
				int num = this._frame - sequence.Start;
				if (num >= 0 && num < sequence.Duration)
				{
					sequence.Event(new FrameEventData(this._frame, sequence.Start, sequence.Duration));
				}
			}
			int num2 = this._frame + 1;
			this._frame = num2;
			return num2 != this._frameCount;
		}

		// Token: 0x06002739 RID: 10041 RVA: 0x0001B730 File Offset: 0x00019930
		public virtual void OnBegin()
		{
			this._isActive = true;
		}

		// Token: 0x0600273A RID: 10042 RVA: 0x0001B739 File Offset: 0x00019939
		public virtual void OnEnd()
		{
			this._isActive = false;
		}

		// Token: 0x0600273B RID: 10043 RVA: 0x00006B58 File Offset: 0x00004D58
		private static void EmptyFrameEvent(FrameEventData evt)
		{
		}

		// Token: 0x040043AC RID: 17324
		private int _frame;

		// Token: 0x040043AD RID: 17325
		private int _frameCount;

		// Token: 0x040043AE RID: 17326
		private int _nextSequenceAppendTime;

		// Token: 0x040043AF RID: 17327
		private bool _isActive;

		// Token: 0x040043B0 RID: 17328
		private List<Film.Sequence> _sequences = new List<Film.Sequence>();

		// Token: 0x0200048A RID: 1162
		private class Sequence
		{
			// Token: 0x170002BE RID: 702
			// (get) Token: 0x0600273D RID: 10045 RVA: 0x0001B755 File Offset: 0x00019955
			public FrameEvent Event
			{
				get
				{
					return this._frameEvent;
				}
			}

			// Token: 0x170002BF RID: 703
			// (get) Token: 0x0600273E RID: 10046 RVA: 0x0001B75D File Offset: 0x0001995D
			public int Duration
			{
				get
				{
					return this._duration;
				}
			}

			// Token: 0x170002C0 RID: 704
			// (get) Token: 0x0600273F RID: 10047 RVA: 0x0001B765 File Offset: 0x00019965
			public int Start
			{
				get
				{
					return this._start;
				}
			}

			// Token: 0x06002740 RID: 10048 RVA: 0x0001B76D File Offset: 0x0001996D
			public Sequence(FrameEvent frameEvent, int start, int duration)
			{
				this._frameEvent = frameEvent;
				this._start = start;
				this._duration = duration;
			}

			// Token: 0x040043B1 RID: 17329
			private FrameEvent _frameEvent;

			// Token: 0x040043B2 RID: 17330
			private int _duration;

			// Token: 0x040043B3 RID: 17331
			private int _start;
		}
	}
}
